// pages/my_yuyue/my_yuyue.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //内容
    wendaArr: [],
    editCon: "编辑",
    a: false,
    edit: false,
  },
  // 切换nav
  swichNav: function(e) {
    var nav = this.data.nav;
    nav.currentTab = e.currentTarget.dataset.current;
    this.setData({
      nav: nav
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var bgc = wx.getStorageSync('color')
    var openid = wx.getStorageSync('openid')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    app.util.request({
      'url': 'entry/wxapp/Alllipei',
      data: {
        openid: openid
      },
      success: function(res) {
        console.log(res)
        that.setData({
          wendaArr: res.data.data
        })
      }
    })
    that.setData({
      backgroundColor: bgc,
    })
  },
  // huanDetailClick:function(){
  //   wx.navigateTo({
  //     url: '/pages/chufang/chufang',
  //   })
  // },
  //编辑 取消
  editClick: function() {
    var that = this
    if (that.data.edit) {
      var editCon = "编辑"
    } else {
      var editCon = "取消"
      var a = false
    }
    that.setData({
      edit: !that.data.edit,
      a: a
    })
  },
  checkboxChange: function(e) {
    console.log('checkbox发生change事件，携带value值为：', e.detail.value)
    var that = this
    if (e.detail.value.length == 0) {
      var a = false
    } else {
      var a = true
    }
    that.setData({
      a: a
    })
  },
  del: function(e) {
    console.log(e)
    var that = this
    var index = e.currentTarget.dataset.index
    var historyArr = that.data.wendaArr
    console.log(historyArr[index].checked)
    if (historyArr[index].checked == 0 || historyArr[index].checked == undefined) {
      historyArr[index].checked = 1
    } else {
      historyArr[index].checked = 0
    }
    that.setData({
      wendaArr: historyArr
    })
  },
  subClick: function(e) {
    console.log(e)
    var that = this
    var historyArr = that.data.wendaArr
    var lpid = e.detail.value.checkBox
    app.util.request({
      'url': 'entry/wxapp/Delelip',
      data: {
        lpid: lpid
      },
      success: function(res) {
        var arrs = res.data.data;
        console.log(res);
      },
      fail: function(err) {
        console.log(err)
      },

    })
    for (var i = 0, len = historyArr.length; i < len; i++) {
      console.log(historyArr[i])
      if (historyArr[i].checked == 1) {
        historyArr.splice(i, 1)
        i--
        len--
      }
    }
    that.setData({
      wendaArr: historyArr
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  lipeils: function(e) {
    console.log(e)
    var lpid = e.currentTarget.dataset.lpid
    wx.navigateTo({
      url: '/hyb_yl/twosubpages/pages/patient2/patient2?lpid=' + lpid,
    })
  }
})